
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.cli.pmg_config &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.cli.pmg_config</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.cli.pmg_config</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Implementation for `pmg config` CLI.</span>
<span class="sd">&quot;&quot;&quot;</span>


<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">glob</span>
<span class="kn">import</span> <span class="nn">shutil</span>
<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">from</span> <span class="nn">monty.serialization</span> <span class="kn">import</span> <span class="n">loadfn</span><span class="p">,</span> <span class="n">dumpfn</span>

<span class="kn">from</span> <span class="nn">pymatgen</span> <span class="kn">import</span> <span class="n">SETTINGS_FILE</span>
<span class="kn">from</span> <span class="nn">urllib.request</span> <span class="kn">import</span> <span class="n">urlretrieve</span>


<div class="viewcode-block" id="setup_potcars"><a class="viewcode-back" href="../../../pymatgen.cli.pmg_config.html#pymatgen.cli.pmg_config.setup_potcars">[docs]</a><span class="k">def</span> <span class="nf">setup_potcars</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Setup POTCAR directirt,</span>

<span class="sd">    :param args: args from command.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">pspdir</span><span class="p">,</span> <span class="n">targetdir</span> <span class="o">=</span> <span class="p">[</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">args</span><span class="o">.</span><span class="n">potcar_dirs</span><span class="p">]</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">targetdir</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">OSError</span><span class="p">:</span>
        <span class="n">r</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s2">&quot;Destination directory exists. Continue (y/n)? &quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">r</span> <span class="o">!=</span> <span class="s2">&quot;y&quot;</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Exiting ...&quot;</span><span class="p">)</span>
            <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>

    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Generating pymatgen resources directory...&quot;</span><span class="p">)</span>

    <span class="n">name_mappings</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;potpaw_PBE&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_GGA_PAW_PBE&quot;</span><span class="p">,</span>
        <span class="s2">&quot;potpaw_PBE_52&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_GGA_PAW_PBE_52&quot;</span><span class="p">,</span>
        <span class="s2">&quot;potpaw_PBE_54&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_GGA_PAW_PBE_54&quot;</span><span class="p">,</span>
        <span class="s2">&quot;potpaw_PBE.52&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_GGA_PAW_PBE_52&quot;</span><span class="p">,</span>
        <span class="s2">&quot;potpaw_PBE.54&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_GGA_PAW_PBE_54&quot;</span><span class="p">,</span>
        <span class="s2">&quot;potpaw_LDA&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_LDA_PAW&quot;</span><span class="p">,</span>
        <span class="s2">&quot;potpaw_LDA.52&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_LDA_PAW_52&quot;</span><span class="p">,</span>
        <span class="s2">&quot;potpaw_LDA.54&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_LDA_PAW_54&quot;</span><span class="p">,</span>
        <span class="s2">&quot;potpaw_LDA_52&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_LDA_PAW_52&quot;</span><span class="p">,</span>
        <span class="s2">&quot;potpaw_LDA_54&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_LDA_PAW_54&quot;</span><span class="p">,</span>
        <span class="s2">&quot;potUSPP_LDA&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_LDA_US&quot;</span><span class="p">,</span>
        <span class="s2">&quot;potpaw_GGA&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_GGA_PAW_PW91&quot;</span><span class="p">,</span>
        <span class="s2">&quot;potUSPP_GGA&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_GGA_US_PW91&quot;</span>
    <span class="p">}</span>

    <span class="k">for</span> <span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">subdirs</span><span class="p">,</span> <span class="n">files</span><span class="p">)</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="n">pspdir</span><span class="p">):</span>
        <span class="n">basename</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>
        <span class="n">basename</span> <span class="o">=</span> <span class="n">name_mappings</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">basename</span><span class="p">,</span> <span class="n">basename</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">subdir</span> <span class="ow">in</span> <span class="n">subdirs</span><span class="p">:</span>
            <span class="n">filenames</span> <span class="o">=</span> <span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">subdir</span><span class="p">,</span> <span class="s2">&quot;POTCAR*&quot;</span><span class="p">))</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">filenames</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">basedir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">targetdir</span><span class="p">,</span> <span class="n">basename</span><span class="p">)</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">basedir</span><span class="p">):</span>
                        <span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">basedir</span><span class="p">)</span>
                    <span class="n">fname</span> <span class="o">=</span> <span class="n">filenames</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="n">dest</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">basedir</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">fname</span><span class="p">))</span>
                    <span class="n">shutil</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="n">dest</span><span class="p">)</span>
                    <span class="n">ext</span> <span class="o">=</span> <span class="n">fname</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;.&quot;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
                    <span class="k">if</span> <span class="n">ext</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;Z&quot;</span><span class="p">,</span> <span class="s2">&quot;GZ&quot;</span><span class="p">]:</span>
                        <span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">([</span><span class="s2">&quot;gunzip&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="p">])</span><span class="o">.</span><span class="n">communicate</span><span class="p">()</span>
                    <span class="k">elif</span> <span class="n">ext</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;BZ2&quot;</span><span class="p">]:</span>
                        <span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">([</span><span class="s2">&quot;bunzip2&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="p">])</span><span class="o">.</span><span class="n">communicate</span><span class="p">()</span>
                    <span class="k">if</span> <span class="n">subdir</span> <span class="o">==</span> <span class="s2">&quot;Osmium&quot;</span><span class="p">:</span>
                        <span class="n">subdir</span> <span class="o">=</span> <span class="s2">&quot;Os&quot;</span>
                    <span class="n">dest</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">basedir</span><span class="p">,</span> <span class="s2">&quot;POTCAR.</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">subdir</span><span class="p">))</span>
                    <span class="n">shutil</span><span class="o">.</span><span class="n">move</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">basedir</span><span class="p">,</span> <span class="s2">&quot;POTCAR&quot;</span><span class="p">),</span> <span class="n">dest</span><span class="p">)</span>
                    <span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">([</span><span class="s2">&quot;gzip&quot;</span><span class="p">,</span> <span class="s2">&quot;-f&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="p">])</span><span class="o">.</span><span class="n">communicate</span><span class="p">()</span>
                <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
                    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;An error has occured. Message is </span><span class="si">%s</span><span class="s2">. Trying to &quot;</span>
                          <span class="s2">&quot;continue... &quot;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">))</span>

    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;PSP resources directory generated. It is recommended that you &quot;</span>
          <span class="s2">&quot;run &#39;pmg config --add PMG_VASP_PSP_DIR </span><span class="si">%s</span><span class="s2">&#39;&quot;</span> <span class="o">%</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">targetdir</span><span class="p">))</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Start a new terminal to ensure that your environment variables &quot;</span>
          <span class="s2">&quot;are properly set.&quot;</span><span class="p">)</span></div>


<div class="viewcode-block" id="build_enum"><a class="viewcode-back" href="../../../pymatgen.cli.pmg_config.html#pymatgen.cli.pmg_config.build_enum">[docs]</a><span class="k">def</span> <span class="nf">build_enum</span><span class="p">(</span><span class="n">fortran_command</span><span class="o">=</span><span class="s2">&quot;gfortran&quot;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Build enum.</span>

<span class="sd">    :param fortran_command:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">currdir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">()</span>
    <span class="n">state</span> <span class="o">=</span> <span class="kc">True</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">([</span><span class="s2">&quot;git&quot;</span><span class="p">,</span> <span class="s2">&quot;clone&quot;</span><span class="p">,</span> <span class="s2">&quot;--recursive&quot;</span><span class="p">,</span>
                         <span class="s2">&quot;https://github.com/msg-byu/enumlib.git&quot;</span><span class="p">])</span>
        <span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">currdir</span><span class="p">,</span> <span class="s2">&quot;enumlib&quot;</span><span class="p">,</span> <span class="s2">&quot;symlib&quot;</span><span class="p">,</span> <span class="s2">&quot;src&quot;</span><span class="p">))</span>
        <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;F90&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">fortran_command</span>
        <span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">([</span><span class="s2">&quot;make&quot;</span><span class="p">])</span>
        <span class="n">enumpath</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">currdir</span><span class="p">,</span> <span class="s2">&quot;enumlib&quot;</span><span class="p">,</span> <span class="s2">&quot;src&quot;</span><span class="p">)</span>
        <span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="n">enumpath</span><span class="p">)</span>
        <span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">([</span><span class="s2">&quot;make&quot;</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;enum.x&quot;</span><span class="p">,</span> <span class="s2">&quot;makestr.x&quot;</span><span class="p">]:</span>
            <span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">([</span><span class="s2">&quot;make&quot;</span><span class="p">,</span> <span class="n">f</span><span class="p">])</span>
            <span class="n">shutil</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s2">&quot;..&quot;</span><span class="p">,</span> <span class="s2">&quot;..&quot;</span><span class="p">))</span>
    <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">))</span>
        <span class="n">state</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="k">finally</span><span class="p">:</span>
        <span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="n">currdir</span><span class="p">)</span>
        <span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="s2">&quot;enumlib&quot;</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">state</span></div>


<div class="viewcode-block" id="build_bader"><a class="viewcode-back" href="../../../pymatgen.cli.pmg_config.html#pymatgen.cli.pmg_config.build_bader">[docs]</a><span class="k">def</span> <span class="nf">build_bader</span><span class="p">(</span><span class="n">fortran_command</span><span class="o">=</span><span class="s2">&quot;gfortran&quot;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Build bader package.</span>

<span class="sd">    :param fortran_command:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">bader_url</span> <span class="o">=</span> <span class="s2">&quot;http://theory.cm.utexas.edu/henkelman/code/bader/download/bader.tar.gz&quot;</span>
    <span class="n">currdir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">()</span>
    <span class="n">state</span> <span class="o">=</span> <span class="kc">True</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">urlretrieve</span><span class="p">(</span><span class="n">bader_url</span><span class="p">,</span> <span class="s2">&quot;bader.tar.gz&quot;</span><span class="p">)</span>
        <span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">([</span><span class="s2">&quot;tar&quot;</span><span class="p">,</span> <span class="s2">&quot;-zxf&quot;</span><span class="p">,</span> <span class="s2">&quot;bader.tar.gz&quot;</span><span class="p">])</span>
        <span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="s2">&quot;bader&quot;</span><span class="p">)</span>
        <span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">(</span>
            <span class="p">[</span><span class="s2">&quot;cp&quot;</span><span class="p">,</span> <span class="s2">&quot;makefile.osx_&quot;</span> <span class="o">+</span> <span class="n">fortran_command</span><span class="p">,</span> <span class="s2">&quot;makefile&quot;</span><span class="p">])</span>
        <span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">([</span><span class="s2">&quot;make&quot;</span><span class="p">])</span>
        <span class="n">shutil</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="s2">&quot;bader&quot;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s2">&quot;..&quot;</span><span class="p">,</span> <span class="s2">&quot;bader_exe&quot;</span><span class="p">))</span>
        <span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="s2">&quot;..&quot;</span><span class="p">)</span>
        <span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="s2">&quot;bader&quot;</span><span class="p">)</span>
        <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s2">&quot;bader.tar.gz&quot;</span><span class="p">)</span>
        <span class="n">shutil</span><span class="o">.</span><span class="n">move</span><span class="p">(</span><span class="s2">&quot;bader_exe&quot;</span><span class="p">,</span> <span class="s2">&quot;bader&quot;</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">))</span>
        <span class="n">state</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="k">finally</span><span class="p">:</span>
        <span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="n">currdir</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">state</span></div>


<div class="viewcode-block" id="install_software"><a class="viewcode-back" href="../../../pymatgen.cli.pmg_config.html#pymatgen.cli.pmg_config.install_software">[docs]</a><span class="k">def</span> <span class="nf">install_software</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Install all optional external software.</span>

<span class="sd">    :param args:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">([</span><span class="s2">&quot;ifort&quot;</span><span class="p">,</span> <span class="s2">&quot;--version&quot;</span><span class="p">])</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Found ifort&quot;</span><span class="p">)</span>
        <span class="n">fortran_command</span> <span class="o">=</span> <span class="s2">&quot;ifort&quot;</span>
    <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">([</span><span class="s2">&quot;gfortran&quot;</span><span class="p">,</span> <span class="s2">&quot;--version&quot;</span><span class="p">])</span>
            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Found gfortran&quot;</span><span class="p">)</span>
            <span class="n">fortran_command</span> <span class="o">=</span> <span class="s2">&quot;gfortran&quot;</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">))</span>
            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;No fortran compiler found.&quot;</span><span class="p">)</span>
            <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

    <span class="n">enum</span> <span class="o">=</span> <span class="kc">None</span>
    <span class="n">bader</span> <span class="o">=</span> <span class="kc">None</span>
    <span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">install</span> <span class="o">==</span> <span class="s2">&quot;enumlib&quot;</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Building enumlib&quot;</span><span class="p">)</span>
        <span class="n">enum</span> <span class="o">=</span> <span class="n">build_enum</span><span class="p">(</span><span class="n">fortran_command</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
    <span class="k">elif</span> <span class="n">args</span><span class="o">.</span><span class="n">install</span> <span class="o">==</span> <span class="s2">&quot;bader&quot;</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Building bader&quot;</span><span class="p">)</span>
        <span class="n">bader</span> <span class="o">=</span> <span class="n">build_bader</span><span class="p">(</span><span class="n">fortran_command</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">bader</span> <span class="ow">or</span> <span class="n">enum</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Please add </span><span class="si">{}</span><span class="s2"> to your PATH or move the executables multinum.x, &quot;</span>
              <span class="s2">&quot;makestr.x and/or bader to a location in your PATH.&quot;</span>
              <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="s2">&quot;.&quot;</span><span class="p">)))</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span></div>


<div class="viewcode-block" id="add_config_var"><a class="viewcode-back" href="../../../pymatgen.cli.pmg_config.html#pymatgen.cli.pmg_config.add_config_var">[docs]</a><span class="k">def</span> <span class="nf">add_config_var</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Add configuration args.</span>

<span class="sd">    :param args:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">d</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">SETTINGS_FILE</span><span class="p">):</span>
        <span class="n">shutil</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">SETTINGS_FILE</span><span class="p">,</span> <span class="n">SETTINGS_FILE</span> <span class="o">+</span> <span class="s2">&quot;.bak&quot;</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Existing </span><span class="si">%s</span><span class="s2"> backed up to </span><span class="si">%s</span><span class="s2">&quot;</span>
              <span class="o">%</span> <span class="p">(</span><span class="n">SETTINGS_FILE</span><span class="p">,</span> <span class="n">SETTINGS_FILE</span> <span class="o">+</span> <span class="s2">&quot;.bak&quot;</span><span class="p">))</span>
        <span class="n">d</span> <span class="o">=</span> <span class="n">loadfn</span><span class="p">(</span><span class="n">SETTINGS_FILE</span><span class="p">)</span>
    <span class="n">toks</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">var_spec</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">toks</span><span class="p">)</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Bad variable specification!&quot;</span><span class="p">)</span>
        <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">toks</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)):</span>
        <span class="n">d</span><span class="p">[</span><span class="n">toks</span><span class="p">[</span><span class="mi">2</span> <span class="o">*</span> <span class="n">i</span><span class="p">]]</span> <span class="o">=</span> <span class="n">toks</span><span class="p">[</span><span class="mi">2</span> <span class="o">*</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
    <span class="n">dumpfn</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">SETTINGS_FILE</span><span class="p">,</span> <span class="n">default_flow_style</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;New </span><span class="si">%s</span><span class="s2"> written!&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">SETTINGS_FILE</span><span class="p">))</span></div>


<div class="viewcode-block" id="configure_pmg"><a class="viewcode-back" href="../../../pymatgen.cli.pmg_config.html#pymatgen.cli.pmg_config.configure_pmg">[docs]</a><span class="k">def</span> <span class="nf">configure_pmg</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Handle configure command.</span>

<span class="sd">    :param args:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">potcar_dirs</span><span class="p">:</span>
        <span class="n">setup_potcars</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
    <span class="k">elif</span> <span class="n">args</span><span class="o">.</span><span class="n">install</span><span class="p">:</span>
        <span class="n">install_software</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
    <span class="k">elif</span> <span class="n">args</span><span class="o">.</span><span class="n">var_spec</span><span class="p">:</span>
        <span class="n">add_config_var</span><span class="p">(</span><span class="n">args</span><span class="p">)</span></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.cli.pmg_config</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>